local FreezeMat = Material( "models/spawn_effect2" )

//Initialize function
function EFFECT:Init(data)

	//How long the effect lasts
	self.Time = 1
	self.LifeTime = CurTime() + self.Time

	//Retrieve target entity
	local ent = data:GetEntity()
	if ( ent == NULL ) then return end

	//Parent to original entity
	self.ParentEntity = ent
	self.Entity:SetModel(ent:GetModel())
	self.Entity:SetPos(ent:GetPos())
	self.Entity:SetAngles(ent:GetAngles())
	self.Entity:SetColor(255, 255, 255, 72)
	self.Entity:SetParent(ent)

end


//Think function
function EFFECT:Think()

//Safeguards
if (!self.ParentEntity || !self.ParentEntity:IsValid()) then return false end

//Kill if overdue
return ( self.LifeTime > CurTime() ) 

end


//Render function
function EFFECT:Render()

	//What fraction towards finishing are we at
	local Fraction = (self.LifeTime - CurTime()) / self.Time
	Fraction = math.Clamp(Fraction, 0, 1)

	//Change the model's alpha so the texture will fade out
	self.Entity:SetColor( 255, 255, 255, 1 + math.sin(Fraction * math.pi) * 100 )

	//Place the camera a bit closer to the entity - avoids Z-fighting
	local EyeNormal = self.Entity:GetPos() - EyePos()
	local Distance = EyeNormal:Length()
	EyeNormal:Normalize()

	//Start a new 3D camera position
	cam.Start3D( (EyePos() + EyeNormal * Distance * 0.01), EyeAngles() )

	//Draw model with the defined material
	SetMaterialOverride(FreezeMat)
	self.Entity:DrawModel()
	SetMaterialOverride(0)

	//Set the camera back to how it was
	cam.End3D()

end